package org.wat.wcy.isi.mmazur.bp.io.xpdl.processors;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.wat.wcy.isi.mmazur.bp.io.model.IdDesc;
import org.wat.wcy.isi.mmazur.bp.io.model.Node;
import org.wat.wcy.isi.mmazur.bp.io.model.TransitionCondition;
import org.wat.wcy.isi.mmazur.bp.io.model.Transition;
import org.wat.wcy.isi.mmazur.bp.io.model.enums.TransitionType;
import org.wat.wcy.isi.mmazur.bp.io.model.temporary.Route;
import org.wat.wcy.isi.mmazur.bp.io.xpdl.IXMLProcessor;
import org.xml.sax.Attributes;

public class MessagesFlowProcessor implements IXMLProcessor {

	
	private Transition currentMsgTransition;
	private Route currentRoute;
	private Map<Route, Transition> msgTransitions;
	
	public MessagesFlowProcessor() {
		msgTransitions = new HashMap<Route, Transition> ();
	}
	
	@Override
	public void startElement(String name, Attributes attr) {
		if (StringUtils.equals(name, "/Package/MessageFlows/MessageFlow")) {
			currentMsgTransition = new Transition();
			String from = attr.getValue("Source");
			String to = attr.getValue("Target");
			String id = attr.getValue("Id");
			currentMsgTransition.setType(TransitionType.MESSAGE);
			currentMsgTransition.setId(new IdDesc(id));
			currentRoute = new Route(from, to);
			currentMsgTransition.setCondition(new TransitionCondition());
		}
	}

	@Override
	public void endElement(String name, String characters) {
		if (StringUtils.equals(name, "/Package/MessageFlows/MessageFlow")) {
			msgTransitions.put(currentRoute, currentMsgTransition);
		}
	}

	@Override
	public Map<String, Node> getNodes() {
		return null;
	}

	@Override
	public Map<Route, Transition> getTransitions() {
		return msgTransitions;
	}

	@Override
	public Map<String, Node> getPools() {
		return null;
	}
}